﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LeHouse.Server.Dto;
namespace LeHouse.Server.Dal
{
    /// <summary>
    /// 户内部分DAL的操作
    /// </summary>
    public class Collateral_IndoorDAL : GenericBaseDAL<Collateral_Indoor>
    {
        /// <summary>
        /// 根据报告号去查询户内是否有该条记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public int IsCount(string P_ReportNumber)
        {
            int C_projectcount;
            string sql = @"select count(T_IndoorID) from Collateral_Indoor  where T_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    C_projectcount = Convert.ToInt32(cmd.ExecuteScalar());
                }
                return C_projectcount;
            }
        }

        /// <summary>
        /// 根据报告号去查询户内的信息
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public Collateral_Indoor Facilitybyid(string P_ReportNumber)
        {
            Collateral_Indoor munity = new Collateral_Indoor();
            string sql = @"select * from Collateral_Indoor  where T_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    var reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            munity.T_ReportNumber = reader["T_ReportNumber"].ToString();
                            munity.T_purposeID = Convert.ToInt32(reader["T_purposeID"]);
                            munity.T_Floor = reader["T_Floor"].ToString();
                            munity.T_Storey = Convert.ToInt32(reader["T_Storey"]);
                            munity.T_OrientationID = Convert.ToInt32(reader["T_OrientationID"]);
                            munity.T_ResidenceID = Convert.ToInt32(reader["T_ResidenceID"]);
                            munity.T_SeveralBedroom = reader["T_SeveralBedroom"].ToString();
                            munity.T_Severaldrawing = reader["T_Severaldrawing"].ToString();
                            munity.T_Severalbathroom = reader["T_Severalbathroom"].ToString();
                            munity.T_SeveralKITCHEN = reader["T_SeveralKITCHEN"].ToString();

                            munity.T_Severalbalcony = reader["T_Severalbalcony"].ToString();
                            munity.T_SeveralTerrace = reader["T_SeveralTerrace"].ToString();
                            munity.T_SeveralSmall = reader["T_SeveralSmall"].ToString();

                            munity.T_DrawingID = Convert.ToInt32(reader["T_DrawingID"]);
                            munity.T_RoomdescribeID = Convert.ToInt32(reader["T_RoomdescribeID"]);
                            munity.T_RoomdescribeInteriorwall = reader["T_RoomdescribeInteriorwall"].ToString();
                            munity.T_RoomdescribeInteriorwallOther = reader["T_RoomdescribeInteriorwallOther"].ToString();
                            munity.T_RoomdescribeCeiling = reader["T_RoomdescribeCeiling"].ToString();
                            munity.T_RoomdescribeCeilingOther = reader["T_RoomdescribeCeilingOther"].ToString();
                            munity.T_RoomdescribeGround = reader["T_RoomdescribeGround"].ToString();
                            munity.T_RoomdescribeGroundOther = reader["T_RoomdescribeGroundOther"].ToString();

                            munity.T_HabitableID = Convert.ToInt32(reader["T_HabitableID"]);
                            munity.T_HabitableInteriorwall = reader["T_HabitableInteriorwall"].ToString();
                            munity.T_HabitableInteriorwallOther = reader["T_HabitableInteriorwallOther"].ToString();
                            munity.T_HabitableCeiling = reader["T_HabitableCeiling"].ToString();
                            munity.T_HabitableCeilingOther = reader["T_HabitableCeilingOther"].ToString();
                            munity.T_HabitableGround = reader["T_HabitableGround"].ToString();
                            munity.T_HabitableGroundOther = reader["T_HabitableGroundOther"].ToString();
                            munity.T_ToiletID = Convert.ToInt32(reader["T_ToiletID"]);
                            munity.T_ToiletInteriorwall = reader["T_ToiletInteriorwall"].ToString();
                            munity.T_ToiletInteriorwallOther = reader["T_ToiletInteriorwallOther"].ToString();
                            munity.T_ToiletCeiling = reader["T_ToiletCeiling"].ToString();
                            munity.T_ToiletCeilingOther = reader["T_ToiletCeilingOther"].ToString();
                            munity.T_ToiletGround = reader["T_ToiletGround"].ToString();
                            munity.T_ToiletGroundOther = reader["T_ToiletGroundOther"].ToString();
                            munity.T_KitchenID = Convert.ToInt32(reader["T_KitchenID"]);
                            munity.T_KitchenInteriorwall = reader["T_KitchenInteriorwall"].ToString();
                            munity.T_KitchenInteriorwallOther = reader["T_KitchenInteriorwallOther"].ToString();
                            munity.T_KitchenCeiling = reader["T_KitchenCeiling"].ToString();
                            munity.T_KitchenCeilingOther = reader["T_KitchenCeilingOther"].ToString();
                            munity.T_KitchenGround = reader["T_KitchenGround"].ToString();
                            munity.T_KitchenGroundOther = reader["T_KitchenGroundOther"].ToString();
                           
                            munity.T_Explain = reader["T_Explain"].ToString();
                        
                          //  munity.T_State = Convert.ToInt32(reader["I_state"]);
                         //   munity = Convert.ToInt32(reader["I_Buildingafew"]);
                                                                                  
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
                return munity;
            }
        }
    }
}
